from django import forms
from web.forms.bootstrap import BootStrap
from web import models
from django.core.exceptions import ValidationError


class ProjectModelForm(BootStrap, forms.ModelForm):
    class Meta:
        model = models.Project

        fields = ['name', 'kind', 'addr', 'desc']

        widgets = {
            'desc': forms.Textarea
        }

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.request = request

    def clean_name(self):
        name=self.cleaned_data['name']
        exists = models.Project.objects.filter(name=name, creator=self.request.user_obj).exists()
        if exists:
            raise ValidationError('该电影您已经分享过')
        return name

class ProjectModelForm2(BootStrap, forms.ModelForm):
    class Meta:
        model = models.UserInfo
        fields = ['username','password','email','mobile_phone']

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.request = request


class ProjectModelForm3(BootStrap, forms.ModelForm):
    class Meta:
        model = models.Project

        fields = ['name']

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.request = request

class ProjectModelForm4(BootStrap, forms.ModelForm):
    class Meta:
        model = models.UserInfo

        fields = ['password','email','mobile_phone']

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.request = request




